package src.mian.java;
import org.apache.hadoop.fs.FSDataInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class MyFSDataInputStream extends FSDataInputStream {
    public MyFSDataInputStream(FSDataInputStream in) {
        super(in);
    }
    public String readLines() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(this,"gbk"));
        return reader.readLine();
    }
    public static void main(String[] args) {
        String hdfsUri = "hdfs://192.168.254.100:8020"; // 替换成您的 HDFS URI
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", hdfsUri);
        try {
            FileSystem fs = FileSystem.get(conf);
            Path filePath = new Path("/test/poem.txt"); // 替换成您要查看的文件路径
            FSDataInputStream in = fs.open(filePath);
            MyFSDataInputStream myIn = new MyFSDataInputStream(in);
            String line;
            while ((line = myIn.readLines()) != null) {
                System.out.println(line);
            }
            myIn.close();
            in.close();
            fs.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}



